#include "stdafx.h"

#include "SkinUtil.h"
#include "SkinStorage.h"

#include "tinyxml.h"

#include "SkinElement.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

CSkinStorage::CSkinStorage()
{
	m_strName = _T("");

	m_rcImage1.SetRect(0,0,0,0);
	m_rcImage2.SetRect(0,0,0,0);
	m_rcImage3.SetRect(0,0,0,0);
	m_rcImage4.SetRect(0,0,0,0);
}

CSkinStorage::~CSkinStorage()
{
}

bool CSkinStorage::LoadStorage(TiXmlNode * pNode)
{
	CString strElementValue;

	strElementValue = CSkinElement::GetXMLElementValue(pNode, "name");

	if( strElementValue.IsEmpty() )		
		return false;

	m_strName = strElementValue;		
		
	strElementValue = CSkinElement::GetXMLElementValue(pNode, "image1");
	if (!strElementValue.IsEmpty())
	{
		CString str = strElementValue;
		CString strTok;

		strTok = NateOnSkinUtil::GetIndexToken(str, _T(","), 0);
		m_rcImage1.left = _ttoi(strTok);

		strTok = NateOnSkinUtil::GetIndexToken(str, _T(","), 1);
		m_rcImage1.top = _ttoi(strTok);

		strTok = NateOnSkinUtil::GetIndexToken(str, _T(","), 2);
		m_rcImage1.right = _ttoi(strTok);

		strTok = NateOnSkinUtil::GetIndexToken(str, _T(","), 3);
		m_rcImage1.bottom = _ttoi(strTok);		
	}

	strElementValue = CSkinElement::GetXMLElementValue(pNode, "image2");
	if (!strElementValue.IsEmpty())
	{
		CString str = strElementValue;
		CString strTok;

		strTok = NateOnSkinUtil::GetIndexToken(str, _T(","), 0);
		m_rcImage2.left = _ttoi(strTok);

		strTok = NateOnSkinUtil::GetIndexToken(str, _T(","), 1);
		m_rcImage2.top = _ttoi(strTok);

		strTok = NateOnSkinUtil::GetIndexToken(str, _T(","), 2);
		m_rcImage2.right = _ttoi(strTok);

		strTok = NateOnSkinUtil::GetIndexToken(str, _T(","), 3);
		m_rcImage2.bottom = _ttoi(strTok);		
	}

	strElementValue = CSkinElement::GetXMLElementValue(pNode, "image3");
	if (!strElementValue.IsEmpty())
	{
		CString str = strElementValue;
		CString strTok;

		strTok = NateOnSkinUtil::GetIndexToken(str, _T(","), 0);
		m_rcImage3.left = _ttoi(strTok);

		strTok = NateOnSkinUtil::GetIndexToken(str, _T(","), 1);
		m_rcImage3.top = _ttoi(strTok);

		strTok = NateOnSkinUtil::GetIndexToken(str, _T(","), 2);
		m_rcImage3.right = _ttoi(strTok);

		strTok = NateOnSkinUtil::GetIndexToken(str, _T(","), 3);
		m_rcImage3.bottom = _ttoi(strTok);		
	}

	strElementValue = CSkinElement::GetXMLElementValue(pNode, "image4");
	if (!strElementValue.IsEmpty())
	{
		CString str = strElementValue;
		CString strTok;

		strTok = NateOnSkinUtil::GetIndexToken(str, _T(","), 0);
		m_rcImage4.left = _ttoi(strTok);

		strTok = NateOnSkinUtil::GetIndexToken(str, _T(","), 1);
		m_rcImage4.top = _ttoi(strTok);

		strTok = NateOnSkinUtil::GetIndexToken(str, _T(","), 2);
		m_rcImage4.right = _ttoi(strTok);

		strTok = NateOnSkinUtil::GetIndexToken(str, _T(","), 3);
		m_rcImage4.bottom = _ttoi(strTok);		
	}
	return true;
}

bool CSkinStorage::GetImageRect( CRect& rc )
{
	return true;
}